package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class SpuController {
    @Autowired
    SpuInfoService spuInfoService;
    @Autowired
    SpuImageService spuImageService;
    @Autowired
    SpuSaleAttrService spuSaleAttrService;
    @Autowired
    SpuSaleAttrValueService spuSaleAttrValueService;
    @Autowired
    BaseSaleAttrService baseSaleAttrService;


    /**
     * spu分页
     * @param pageNum
     * @param pageSize
     * @param category3Id
     * @return
     */
    @GetMapping("{page}/{limit}")
    public Result getSpuPage(@PathVariable("page") Long pageNum,
                             @PathVariable("limit") Long pageSize,
                             @RequestParam("category3Id") Long category3Id){
        Page<SpuInfo> spuInfoPage = new Page<>(pageNum, pageSize);
        QueryWrapper<SpuInfo> spuInfoQueryWrapper = new QueryWrapper<>();
        spuInfoQueryWrapper.eq("category3_id", category3Id);
        Page<SpuInfo> page = spuInfoService.page(spuInfoPage, spuInfoQueryWrapper);
        return Result.ok(page);
    }

    /**
     * 添加spu
     * @param spuInfo
     * @return
     */
    @PostMapping("/saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfo spuInfo){

        spuInfoService.saveSpuInfo(spuInfo);
        return Result.ok();
    }
}
